$(function() {
	artist_index.run();
});

var artist_index = {
	run : function() {
		this._init_();
		this._start_();
		this._init_events();
	},

	_init_ : function() {
		this.scrollPage = 1;		
		this.pageCount = $("#pageCount").val() || 0;
	},

	_start_ : function() {
		//考虑大屏问题
		if($(window).height() >= $(document).height()){
			this._query_artists();
		}
	},

	_init_events : function() {		
		$.scroll(function(){
			artist_index._query_artists();
		});
	},
	
	_query_artists: function(){
		if( ! this._has_more_artists()){
			return;
		}
		
		this.scrollPage += 1;        
    	var data = "page=" + this.scrollPage;
		var url = main.contextPath + "/music/artists/query";
		var $loading = $("#artist_list_div > div.loadingBox");
		$.ajax({
			url: url,
			data: data,					
			beforeSend: function(){
				$loading.show();
			},
			success: function(result){
				$("#artist_list_sub_div").append(result);
			}, 
			complete: function(){
				$loading.hide();
			}
		});
	},
	
	_has_more_artists: function(){
		return this.pageCount > 0 && this.scrollPage < this.pageCount;		
	}
};